//
//  InfoTwoDirViewController.m
//  OA
//
//  Created by apple on 15-11-18.
//  Copyright (c) 2015年 net. All rights reserved.
//

#import "InfoTwoDirViewController.h"
#import "AppDelegate.h"
#import "Constants.h"

@implementation InfoTwoDirViewController

NSMutableArray * twoDirs;
AppDelegate * appDelegate;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title=@"二级目录";
    self.table.dataSource= self;
    self.table.delegate = self;
    twoDirs = [[NSMutableArray alloc] init];
    appDelegate = [UIApplication sharedApplication].delegate;
    NSDictionary * params = @{@"infoOneDirId":self.infoOneDirId};
    [appDelegate.manager
     GET:url4
     parameters:params
     success:^(AFHTTPRequestOperation *operation, id responseObject) {
         //oneDirs = responseObject;
         [twoDirs addObjectsFromArray:responseObject];
         //NSLog(@"%d",[oneDirs count]);
         [self.table reloadData];
     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         NSLog(@"获取服务器响应出错！");
     }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return twoDirs.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"twoDirCell" forIndexPath:indexPath];
    cell.layer.cornerRadius=12;
    cell.layer.masksToBounds=YES;
    UILabel * label = (UILabel*)[cell viewWithTag:1];
    label.text = [[twoDirs objectAtIndex:indexPath.row] objectForKey:@"dirName"];
    return cell;
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    id destController = segue.destinationViewController;
    NSIndexPath * indexpath = [self.table indexPathForSelectedRow];
    NSString * twodirid = [[twoDirs objectAtIndex:indexpath.row] objectForKey:@"id"];
    NSString * module = [[twoDirs objectAtIndex:indexpath.row] objectForKey:@"module"];
    [destController setValue:twodirid forKey:@"twoDirId"];
    [destController setValue:module forKey:@"module"];
}

@end
